import numpy as np
from scipy.interpolate import interp1d

class csst_slew:
    def __init__(self, slew_opt=0, kind='linear'):
        print('COSAT:csst_slew> slew_opt = {}'.format(slew_opt))
        self.slew_angles = np.array([0.0, 1.0, 20.0, 45.0, 180])
        self.slew_times  = self.initSlewTime(slew_opt)
        self.fun_slew_time = interp1d(self.slew_angles, self.slew_times, kind=kind)

    def initSlewTime(self, slew_opt=0):
        slew_times = None
        if slew_opt == 0:
            slew_times = np.array([45,45,100,170,-1])
        elif slew_opt == 1:
            slew_times = np.array([44,44,104,184,-1])
        elif slew_opt == 2:
            slew_times = np.array([41,41, 96,168,-1])
        elif slew_opt == 3:
            slew_times = np.array([70,80,130,200,-1])
        elif slew_opt == 4:
            slew_times = np.array([70,80,150,200,-1])

        slew_times[4] = slew_times[3] + (180-45) / 0.35

        # print('debug> slew_opt:{}, slew_times = {}'.format(slew_opt,slew_times))

        return slew_times

    def getSlewTime(self, slew_ang):
        return self.fun_slew_time(slew_ang)

    def printSlewOpts(self):
        for i in range(5):
            slew_times = self.initSlewTime(slew_opt=i)
            print('COSAT:csst_slew:slew_opt = {}'.format(i))
            print('>  slew_angles(degs) slew_time(seconds)')
            for j in range(len(slew_times)):
                print('\t{:>8.2f}  {:>8.2f}'.format(self.slew_angles[j], slew_times[j]))